home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: question on pass-by-reference
- Date: Thu, 18 Jan 96 13:13:31 GMT
- Organization: none
- Message-ID: <821970811snz@genesis.demon.co.uk>
- References: <4dha4j$4qg@shrike.depaul.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4dha4j$4qg@shrike.depaul.edu>
- kmurakam@shrike.depaul.edu "Kazuki Murakami" writes:
-
- >I have a question on pass-by-reference.
-
- You mean passing pointers. C doesn't support any form of pass by reference.
-
- >Here is a problem, I want to set array of unsigned short number to be all 0
- > using a function.
- >here is what set looks like:
- > typedef unsigned short USHORT;
- > typedef USHORT SET[32];
-
- Because of the way C handles arrays typedefing them can lead to a great
- deal of confusion - it is generally best to avoid doing this.
-
- >here is the setInit, which will initialize set to be 0,
- > void setInit (SET *s)
- > {
- > int i;
- >
- > for (i=0; i<32; i++)
- > {
- > *s[i] = 0;
-
- This needs to be:
-
- (*s)[i] = 0;
- > }
- > }
- >
- >here is the calling function.
- > setInit(&set1); setInit(&set2);
- >
- >I think there is somthing wrong in "setInit" function but I cannot seem to
- > figure out what that is.
-
- Your code was trying walk through an array of sets whereas you wanted to
- walk through the elements of a single set.
-
- >If somebody can figure out what that is or some other way of initializing "SET
-
- #include <string.h>
-
- void setInit (SET *s)
- {
- memset(s, 0, sizeof(SET));
- }
-
- or
-
- void setInit (SET s)
- {
- memset(s, 0, sizeof(SET));
- }
-
- which would be called with, say:
-
- setInit(set1); setInit(set2);
-
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-